/**
 * 
 */
package testy;

import gnu.io.SerialPort;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cii_lib.drivers.ktpUART;

/**
 * @author pawel.drabik
 * 
 */
public class USB_testHardware implements cii_lib.CCII_INTERFACE {
	
	private static final Logger log = LoggerFactory
			.getLogger(USB_testHardware.class);

	private String commName = "COM15";
	public static int adrLen = 16;
	public static int dataLen = 16;

	/*
	 * (non-Javadoc)
	 * 
	 * @see cii_lib.CCII_INTERFACE#HardwareRead(long)
	 */
	@Override
	public long HardwareRead(long addr) {
		long ret = -1;
		try {
			ktpUART UART = ktpUART.connect(commName, 921600,
					SerialPort.STOPBITS_1, USB_testHardware.adrLen,
					USB_testHardware.dataLen);
			ret = UART.ii_read(new Integer("" + addr));
			UART.getSerialPort().close();
		} catch (Exception e) {
			log.error("", e);
		}
		log.info("Reading hardware address:{} result:{}", new String[]{Long.toString(addr), Long.toString(ret)});
		return ret;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cii_lib.CCII_INTERFACE#HardwareWrite(long, long)
	 */
	@Override
	public void HardwareWrite(long addr, long data) {
		try {
			log.info("Writing hardware address:{} data:{}", new String[]{Long.toString(addr), Long.toString(data)});
			ktpUART UART = ktpUART.connect(commName, 921600,
					SerialPort.STOPBITS_1, USB_testHardware.adrLen,
					USB_testHardware.dataLen);
			UART.ii_write(addr, data);
			UART.getSerialPort().close();
		} catch (Exception e) {
			log.error("", e);
		}
	}

}
